package com.planet.goods.dao;

import com.planet.goods.pojo.Sku;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import pojo.OrderItem;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface SkuMapper extends Mapper<Sku> {
    @Select("SELECT * FROM tb_sku WHERE NAME LIKE #{name}")
    List<Sku> searchByName(String name);

    /**
     * 递减库存
     * @param orderItem
     * @return
     */
    @Update("UPDATE tb_sku SET num=num-#{num},sale_num=sale_num+#{num} " +
            "WHERE id=#{skuId} AND num>=#{num}")
    int decrCount(OrderItem orderItem);
}
